// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html


import CCMP from "../object/CCMP";
import { SCRIPT_NAME, selfCls } from "./Decorator";






const {ccclass, property} = cc._decorator;

@selfCls
export abstract class Manager extends CCMP {

    private static _ins:any = null;
    public static ins<T extends Manager>(c:{new():T}):T {
        if (this._ins == null) {
            let go = new cc.Node();
            this._ins = go.addComponent(c);
            this._ins.node.name = c[SCRIPT_NAME]();
            this._ins.parentRoot.addChild(go);
        }
        return this._ins as T;
    }

    abstract get parentRoot():cc.Node;
    async init(args?: any): Promise<void> {
        await this.do();
        this.isRunning = true;
    }

    async do() {

    }
}
